package com.example.day20_zhongji.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.day20_zhongji.R;
import com.example.day20_zhongji.bean.ArticleBean;
import com.example.day20_zhongji.bean.BannerBean;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;
public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
    private Context context;
    private List<ArticleBean.DataBean.DatasBean> datas;
    private List<BannerBean.DataBean> banner1;
    private int ban=1;
    private int data=2;

    public HomeAdapter(Context context, List<ArticleBean.DataBean.DatasBean> datas, List<BannerBean.DataBean> banner1) {
        this.context = context;
        this.datas = datas;
        this.banner1 = banner1;
    }

    @NonNull
    @Override
    public HomeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
     /* if (viewType==ban){
            View inflate = LayoutInflater.from(context).inflate(R.layout.banner, null);
            return new ViewHolder(inflate);
        }else {
            View inflate = LayoutInflater.from(context).inflate(R.layout.home_item, null);
            return new ViewHolder1(inflate);
        }*/
        View inflate = LayoutInflater.from(context).inflate(R.layout.home_item, null);
        return new ViewHolder1(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        /* if (getItemViewType(position)==ban){
             ArrayList<String> strings = new ArrayList<>();
             for (int i = 0; i < banner.size(); i++) {
                 String imagePath = banner.get(i).getImagePath();
                 strings.add(imagePath);
             }
           holder.banner.setImages(strings).setImageLoader(new ImageLoader() {
                 @Override
                 public void displayImage(Context context, Object path, ImageView imageView) {
                     Glide.with(context).load(path).into(imageView);
                 }
             }).start();
        }else{*/
             ArticleBean.DataBean.DatasBean datasBean = datas.get(position);
             ViewHolder1 holder1= (ViewHolder1) holder;
             holder1.tilte.setText(datasBean.getChapterName()+"");
             holder1.shi.setText(datasBean.getNiceDate()+"");
             holder1.dsec.setText(datasBean.getTitle()+"");
       // }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    @Override
    public int getItemViewType(int position) {
        if (ban==position){
            return ban;
        }else if (ban!=position){
            return position-1;
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        Banner baner;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            baner=itemView.findViewById(R.id.home_banner);
        }
    }

    private class ViewHolder1 extends ViewHolder {
        TextView tilte;
        TextView dsec;
        TextView shi;
        public ViewHolder1(View inflate) {
            super(inflate);
            tilte=inflate.findViewById(R.id.item_title);
            dsec=inflate.findViewById(R.id.item_desc);
            shi=inflate.findViewById(R.id.shi);

        }
    }
}
